package com.hewep.kit;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class CacheKit {
	public static String REMARK_COLUMN = "remark_column";
	public static String COLUMN_REMARK = "column_remark";
	public static Map<String, Map<String, String>> tableColumns = new HashMap<String, Map<String, String>>();
	public static String COLUMNS = "columns";
	
	// 获取 字段 , 注释
	public static Map<String, String> getColumnRemark(String tableName){
		Map<String, String> map = null;
		Map<String, String> map2 = tableColumns.get(tableName);
		if(map2 != null){
			String json = map2.get(COLUMN_REMARK);
			map = Gsonkit.getMap(json);
		}
		return map;
	}
	// 根据 汉语注释 , 获取字段名称
	public static String getColumnByRemark(String tableName, String remark){
		String temp = "";
		Map<String, String> map2 = tableColumns.get(tableName);
		if(map2 != null){
			String json = map2.get(REMARK_COLUMN);
			Map<String, String> map = Gsonkit.getMap(json);
			temp = map.get(remark);
		}
		return temp;
	}
	
	// 根据字段名称获取 注释
	public static String getRemarkByColumn(String tableName, String column){
		String temp = "";
		Map<String, String> map2 = tableColumns.get(tableName);
		if(map2 != null){
			String json = map2.get(COLUMN_REMARK);
			Map<String, String> map = Gsonkit.getMap(json);
			temp = map.get(column);
		}
		return temp;
	}
	
	public static void cacheByTableName(String tableName, String name, String json){
		Map<String, String> map = tableColumns.get(tableName);
		if(map == null){
			map = new HashMap<String, String>();
		}
		map.put(name, json);
		tableColumns.put(tableName, map);
	}
	
	public static String[] getColumns(String tableName){
		String[] columns = null;
		Map<String, String> map2 = tableColumns.get(tableName);
		if(map2 != null){
			String json = map2.get(COLUMNS);
			columns = json.split(",");
		}
		return columns;
	}
}
